package com.atstudent.gmall.cart.rpc;

import com.atstudent.gmall.cart.biz.CartBizService;
import com.atstudent.gmall.cart.vo.AddCartSuccessVo;
import com.atstudent.gmall.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 购物车远程接口
 * @Author 薛有朋
 * @CreatDate 2025/4/8 20:05
 **/
@Slf4j
@RestController
@RequestMapping(value = "api/inner/cart")
public class CartRpcController {

    @Autowired
    private CartBizService cartBizService;

    /**
     * 添加商品到购物车
     * @Author 薛有朋
     * @Date 2025/4/8 20:17
     **/
    @GetMapping(value = "/addCart")
    public Result<AddCartSuccessVo> addCart(@RequestParam(value = "skuId") Long skuId ,
                                            @RequestParam(value = "skuNum") Integer skuNum){
        log.info("skuId: {} , skuNum: {}" , skuId , skuNum);
        AddCartSuccessVo addCartSuccessVo = cartBizService.addCart(skuId , skuNum);
        return Result.ok(addCartSuccessVo);
    }

    /**
     * 删除选中的商品
     * @Author 薛有朋
     * @Date 2025/4/21 20:20
     **/
    @DeleteMapping(value = "/deleteAllChecked")
    public Result deleteAllChecked(){
        cartBizService.deleteAllChecked();
        return Result.ok();
    }
}
